# coding: utf-8
from typing import List, Union

from PySide6.QtCore import Qt
from PySide6.QtGui import QPixmap

from common import OthersIcon
from components import ScrollAreaWidget, CarouselMapWidget, PlaylistGalleryWidget, CentreImageLabel


class ListInterface(ScrollAreaWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.slidingWidget = CarouselMapWidget(self)
        self.playlistGallery = PlaylistGalleryWidget(self)

        self.__initWidgets()
        self.initDefaultData()

    def __initWidgets(self):
        self.slidingWidget.setFixedHeight(400)
        self.slidingWidget.start()
        self.setObjectName('ListInterface')
        self.verticalLayout.addWidget(self.slidingWidget, 0, Qt.AlignmentFlag.AlignTop)
        self.verticalLayout.addWidget(self.playlistGallery, 0, Qt.AlignmentFlag.AlignTop)

    def addPlaylist(self, title: str, body: str, pixmaps: List[Union[QPixmap, str]]):
        self.playlistGallery.addGridWidget(title, body, pixmaps)

    def initDefaultData(self):
        def addImageLabel(pixmap: str):
            imageLabel = CentreImageLabel(pixmap, self)
            imageLabel.setBorderRadius(10, 10, 10, 10)
            return imageLabel

        self.slidingWidget.addWidgets(
            [addImageLabel(OthersIcon.Default.path()), addImageLabel(OthersIcon.Default1.path())])

        self.addPlaylist('爵士合集', '塞尔焦', [OthersIcon.Default.path() for _ in range(4)])
        self.addPlaylist('爵士合集', '塞尔焦', [OthersIcon.Default1.path() for _ in range(4)])
        self.addPlaylist('爵士合集', '塞尔焦', [OthersIcon.Default2.path() for _ in range(4)])
        self.addPlaylist('爵士合集', '塞尔焦', [OthersIcon.Default3.path() for _ in range(4)])
